package com.ucode.cgms.service;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ucode.cgms.mapper.CgmsGiftRewardOrderMapper;
import com.ucode.model.cgms.CgmsGiftRewardOrder;
import com.ucode.model.cgms.CgmsGiftRewardOrder;
import com.ucode.model.cgms.enums.CgmsSysResultCodeEnum;
import com.ucode.springboot.starter.mybatis.core.base.BaseService;
import com.ucode.tool.base.enums.GlobalResultCodeEnum;
import com.ucode.tool.exception.UcodeServiceException;

import java.time.LocalDateTime;

/**
 * 礼物打赏订单Service
 * @Author: liliang
 * @Date: 2025/5/11 22:40
 * @Version: 1.0
 */
public interface CgmsGiftRewardOrderService extends BaseService<Long, CgmsGiftRewardOrder, CgmsGiftRewardOrderMapper> {

    /**
     * 支付成功回调
     * @param orderId
     * @param payOrderId
     * @param payType
     * @param payTime
     * @param payAmount
     */
    public void paySuccess(Long orderId, Long payOrderId, String payType, LocalDateTime payTime, Integer payAmount);

    /**
     * 【系统】取消订单
     * @param id
     */
    public void cancel(Long id);

    /**
     * 【会员】取消订单
     * @param userId
     * @param id
     */
    public void cancelByMember(Long userId, Long id);
    
    /**
     * 【会员】删除订单
     * @param userId
     * @param id
     */
    public int deleteByMember(Long userId, Long id);

    /**
     * 校验
     * @param id
     * @return
     */
    public default CgmsGiftRewardOrder validate(Long id){
        if(ObjectUtil.isNull(id) )
            throw new UcodeServiceException(GlobalResultCodeEnum.VALIDATE_FAILED);
        //验证数据是否存在
        CgmsGiftRewardOrder bean = this.selectByPrimaryKey(id);
        if(ObjectUtil.isNull(bean) || bean.getDeltag()){
            throw new UcodeServiceException(CgmsSysResultCodeEnum.COMPANION_ORDER_NOT_EXISTS);
        }
        return bean;
    }

    /**
     * 校验
     * @param id
     * @return
     */
    public default CgmsGiftRewardOrder validate(Long id,Long userId){
        CgmsGiftRewardOrder bean = this.validate(id);

        if(!ObjUtil.equals(bean.getCompanionUserId(),userId)){
            throw new UcodeServiceException(GlobalResultCodeEnum.UN_DATA_PERMISSION);
        }
        return bean;
    }

}
